package com.doge.calcalbum.business.calc

import com.doge.calcalbum.utils.spReadBoolean
import com.doge.calcalbum.utils.spReadString
import com.doge.calcalbum.utils.spWrite

object CalcPwdHelper {
    private const val folder = "xyz"
    private const val keyPwd = "m"
    private const val keyReset = "x"
    val hasPwd: Boolean get() = spReadString(keyPwd, null, folder)?.isNotEmpty() == true
    val pwd: String? get() = spReadString(keyPwd, null, folder)
    fun check(pwd: String): Boolean = spReadString(keyPwd, null, folder) == pwd
    fun set(pwd: String) = spWrite(keyPwd, pwd, folder)
    val resettingPwd: Boolean get() = spReadBoolean(keyReset, false, folder)
    fun reset() = spWrite(keyReset, true, folder)
    fun resetCompleted() {
        spWrite(keyReset, false, folder)
        spWrite(keyPwd, null, folder)
    }
}